package leetcode

//https://leetcode.com/problems/remove-element/

fun main() {

    val nums = intArrayOf(0, 1, 2, 2, 3, 0, 4, 2)
//    switchAfter(1, nums)
    removeElement(nums, 2)
    println(nums.asList())
}

fun removeElement(nums: IntArray, `val`: Int): Int {

    var count = nums.size
    var i = 0
    while (i < count) {
        if (nums[i] == `val`) {
            count--
            switchAfter(i, nums)
        } else
            i++
    }
    return count
}